<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@include file="../base.jsp"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户查询</title>    
<link href="../css/main.css" rel="stylesheet" type="text/css" >
<link rel="stylesheet" type="text/css" href="${path}/js/jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${path}/js/jquery/easyui/themes/icon.css">
<script type="text/javascript" src="${path}/js/jquery-1.8.0.min.js"></script>
<script src="${path}/js/jquery/easyui/jquery.easyui.min.js"></script>
<script src="../../js/jquery/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${path}/js/jquery.select.js"></script>
<script type="text/javascript">
function editRow(rowIndex){
	var row = $('#userList').datagrid('getData').rows[rowIndex];
	var id = row.id;
}

var datagrid={
    datagridId:"userList",
    datagridUrl:"userAjax_queryUserListBySearch.action",
    datagridObj:{
        /*title:"查询列表",*/
        nowrap:true,
        autoRowHeight:false,
        fit:true,
        columns:[
            [
             	{field:'id',title:'ID'},
                {field:'loginname',title:'用户名'},
                {field:'name',title:'姓名'},
                {field:'sexStr',title:'性别'},
                {field:'email',title:'邮箱'},
                {field:'telephone',title:'电话'},
                {field:'enabledStr',title:'用户状态'},
                {field:'statusStr',title:'审核状态'},
                {field:'createTimeStr',title:'注册时间'},
                {field:'roleStr',title:'角色',},
                {field:'opt',title:'操作',width:100,align:'center',  
		            formatter:function(value,rowData,rowIndex){  
		                var btn = '<a class="editcls" onclick="editRow(\''+rowIndex+'\')" href="javascript:void(0)">编辑</a>';  
		                return btn;  
		            }  
		        }  
            ]
        ],
		frozenColumns:[[
		                {field:'cb',checkbox:true}
					]],
		toolbar:[
                 {
                     id:'toolbar_add',
					 text:'添加',
					 iconCls:'icon-add',
					 handler:function(){
                	  	toolbar_add();
					 }
                  },
                  "-",
                 {
                     id:'approval',
					 text:'审核通过',
					 iconCls:'icon-pencil',
					 handler:function(){
                	  	approval();
					 }
                  },
                  "-",
                 {
                     id:'disabled',
					 text:'失效',
					 iconCls:'icon-pencil',
					 handler:function(){
                	 	disabled();
					 }
                  },
                  {
                      id:'enabled',
                      text:'有效',
                      iconCls:'icon-pencil',
                      handler:function(){
                         enabled();
                      }
                   },
                  "-",
                  {
                      id:'bindRoleToEmp',
 					 text:'授权',
 					 iconCls:'icon-pencil',
 					 handler:function(){
                	  	bindRoleToEmp();
 					 }
                   }
        ],					
        rownumbers:true
    },
    datagridProperty:{
    	loginname:'用户名',
    	name:'姓名',
    	enabled:'用户状态',
    	status:'审核状态',
    	recordDateStart:'创建日期(起)',
    	recordDateEnd:'创建日期(止)'
    },
    datagridPropertySort:{
        id:'默认属性'
    },
    datagridPropertyMultiQuery:{
    	enabled:'用户状态',
    	status:'审核状态'
    }
};


function approval(){
	var rows = $('#userList').datagrid('getSelections');
	if(rows.length!=1){
		alert('只能选择一项进行操作');
		return false;
	}
	var id = rows[0].id;

	$.ajax({
		type:"POST",
		url:"userAjax_approval.action",
		dataType:"json",
		data:{'empId':id},
		success:function(msg){
			var msg = eval("("+msg+")"); 
			if(msg.responseCode==0){
				alert(msg.responseContent);
				return;
			}			
			if(confirm('操作成功\r\n是否刷新数据?')){
					reLoadData(); 
			}	
			return;
		},
		error:function(er){
			alert('系统出错');
		}
	  });
	
}

function disabled(){
	var rows = $('#userList').datagrid('getSelections');
	if(rows.length!=1){
		alert('只能选择一项进行操作');
		return false;
	}
	var id = rows[0].id;

	$.ajax({
		type:"POST",
		url:"userAjax_disabled.action",
		dataType:"json",
		data:{'empId':id},
		success:function(msg){
			var msg = eval("("+msg+")"); 
			if(msg.responseCode==0){
				alert(msg.responseContent);
				return;
			}			
			if(confirm('操作成功\r\n是否刷新数据?')){
					reLoadData(); 
			}	
			return;
		},
		error:function(er){
			alert('系统出错');
		}
	  });
}

function enabled(){
    var rows = $('#userList').datagrid('getSelections');
    if(rows.length!=1){
        alert('只能选择一项进行操作');
        return false;
    }
    var id = rows[0].id;

    $.ajax({
        type:"POST",
        url:"userAjax_enabled.action",
        dataType:"json",
        data:{'empId':id},
        success:function(msg){
            var msg = eval("("+msg+")"); 
            if(msg.responseCode==0){
                alert(msg.responseContent);
                return;
            }           
            if(confirm('操作成功\r\n是否刷新数据?')){
                    reLoadData(); 
            }   
            return;
        },
        error:function(er){
            alert('系统出错');
        }
      });
}

function bindRoleToEmp(){
	var rows = $('#userList').datagrid('getSelections');
	if(rows.length!=1){
		alert('只能选择一项进行操作');
		return false;
	}
	var id = rows[0].id;
	var loginname = rows[0].loginname;
	
	window.parent.Open('授权[用户名:'+loginname+']','user/bindRoleToEmp.jsp?empId='+id);
}

function toolbar_add(){
}

</script>

<style type="text/css">
	.west{
		width: 200px;
		padding: 3px;
	}
	.north{
		height:70px;
		padding:3px;
	}
	.center{
		padding: 3px;
	}
</style>
</head>


<s:select 
    cssStyle="display: none;"
    id="enabledTmp"
    list="#{1:'有效',0:'无效',-1:'注销'}" 
    listKey="key" 
    listValue="value"/>
    
<s:select 
    cssStyle="display: none;"
    id="statusTmp"
    list="#{2:'审核通过',1:'待审核',-1:'审核失败'}" 
    listKey="key" 
    listValue="value"/>
    

<body class="easyui-layout" style="margin: 2px;">
	<div region="north" class="north" >
        <jsp:include page="../conditionNorth.jsp"></jsp:include>
	</div>
	<div region="center" class="center">
         <table id="userList" width="100%" ></table>
	</div>
	
	
</body>    
</html>